using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
	public static class DateCultureInfoHelper
	{
		public static string CustomDateFormat(bool returnWithHour)
		{
			string datePattern;
			string dateConvert = "";
			datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace(CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator, "");
			while (datePattern.IndexOf("dd") != -1)
			{
				datePattern = datePattern.Replace("dd", "d");
			}
			while (datePattern.IndexOf("MM") != -1)
			{
				datePattern = datePattern.Replace("MM", "M");
			}
			while (datePattern.IndexOf("yy") != -1)
			{
				datePattern = datePattern.Replace("yy", "y");
			}
			switch (datePattern)
			{
				case "dMy":
					dateConvert = "dd.MM.yyyy";
					break;
				case "dyM":
					dateConvert = "dd.yyyy.MM";
					break;
				case "Myd":
					dateConvert = "MM.yyyy.dd";
					break;
				case "Mdy":
					dateConvert = "MM.dd.yyyy";
					break;
				case "yMd":
					dateConvert = "yyyy.MM.dd";
					break;
				case "ydM":
					dateConvert = "yyyy.dd.MM";
					break;
			}

            if (returnWithHour)
                dateConvert += " HH:mm:ss";
 
			return dateConvert;
		}

		public static string CustomMonthFormat(bool returnWithHour)
		{
			string datePattern;
			string dateConvert = "";
			datePattern = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace(CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator, "");
			while (datePattern.IndexOf("dd") != -1)
			{
				datePattern = datePattern.Replace("dd", "d");
			}
			while (datePattern.IndexOf("MM") != -1)
			{
				datePattern = datePattern.Replace("MM", "M");
			}
			while (datePattern.IndexOf("yy") != -1)
			{
				datePattern = datePattern.Replace("yy", "y");
			}
			switch (datePattern)
			{
				case "dMy":
					dateConvert = "MM.yyyy";
					break;
				case "dyM":
					dateConvert = "yyyy.MM";
					break;
				case "Myd":
					dateConvert = "MM.yyyy";
					break;
				case "Mdy":
					dateConvert = "MM.yyyy";
					break;
				case "yMd":
					dateConvert = "yyyy.MM";
					break;
				case "ydM":
					dateConvert = "yyyy.MM";
					break;
			}

			if (returnWithHour)
				dateConvert += " HH:mm:ss";

			return dateConvert;
		}
	}
}